package com.yunfangdata.web.controller;

import com.yunfangdata.domain.RecruitPlan;
import com.yunfangdata.query.RecruitQueryObject;
import com.yunfangdata.service.IRecruitPlanService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import com.yunfangdata.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("recruit")
public class RecruitPlanController {


    @Autowired
    private IRecruitPlanService service;


    @RequiresPermissions("recruit:index")
    @PermissionName("招聘计划首页")
    @RequestMapping("")
    public String index() {

        return "recruitPlan/list";
    }

      @RequiresPermissions("recruit:list")
    @PermissionName("招聘计划列表")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(RecruitQueryObject qo) {

        return  service.query(qo);
    }


    @RequiresPermissions("recruit:changeState")
    @PermissionName("招聘计划列表审核")
    @RequestMapping("changeState")
    @ResponseBody
    public JsonResult changeState(RecruitQueryObject qo) {
        JsonResult js =new JsonResult();
        try {
            service.changeState(qo);
        } catch (Exception e) {
            e.printStackTrace();
            js =new JsonResult("审核失败");
        }
        return js;
    }

    @RequiresPermissions("recruit:removeRecruit")
    @PermissionName("招聘计划列表删除")
    @RequestMapping("removeRecruit")
    @ResponseBody
    public JsonResult removeRecruit(Long id) {
        JsonResult js =new JsonResult();
        try {
            service.removeRecruit(id);
        } catch (Exception e) {
            e.printStackTrace();
            js =new JsonResult("删除失败");
        }
        return js;
    }



    @RequiresPermissions("recruit:firstsave")
    @PermissionName("招聘计划列表添加")
    @RequestMapping("firstSave")
    @ResponseBody
    public JsonResult firstSave() {
        JsonResult js =new JsonResult();
        try {
            service.firstSave();
        } catch (Exception e) {
            e.printStackTrace();
            js =new JsonResult("新增失败");
        }
        return js;
    }


    @RequiresPermissions("recruit:save")
    @PermissionName("招聘计划列表添加")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(RecruitPlan recruitPlan) {
        JsonResult js =new JsonResult();
        try {
            service.save(recruitPlan);
        } catch (Exception e) {
            e.printStackTrace();
            js =new JsonResult("新增失败");
        }
        return js;
    }


    @RequiresPermissions("recruit:save")
    @PermissionName("招聘计划列表更新")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(RecruitPlan recruitPlan) {
        JsonResult js =new JsonResult();
        try {
            service.update(recruitPlan);
        } catch (Exception e) {
            e.printStackTrace();
            js =new JsonResult("更新失败");
        }
        return js;
    }



}
